package com.tanhua.interceptor;

/**
 * @author 杰哥不要啦~
 * @date 2021/10/28
 */

import com.tanhua.model.dimain.User;

/**
 * 工具类实现向theadlocal储存数据的方式
 */
public class UserHolder {

    private static ThreadLocal<User> t1 = new ThreadLocal();

    //  将用户对象存入ThreadLocal
    public static void set(User user){
        t1.set(user);
    }
    //从当前线程取出用户对象
    public static User get(){
        return t1.get();
    }
    //从当前线程取出用户id
    public static Long getUserid(){
        return t1.get().getId();
    }
    //从当前线程取出用户手机号
    public static String getMobile(){
        return t1.get().getMobile();
    }

    //清空
    public static void remove(){
        t1.remove();
    }
}
